/**
 * 
 */
package com.qc.ds.controller.backstage;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.qc.ds.pojo.Category;
import com.qc.ds.pojo.AdminInfo;
import com.qc.ds.services.CategoryService;
import com.qc.ds.util.Const;

@Controller
@RequestMapping("/manager/category/")
public class CategoryController {

	@Autowired
	private CategoryService categoryService;
/**
 * @date 2017��8��4��) ����6:58:58
 * @Package com.qc.ds.controller.backstage 
 * @Description: TODO//��ѯ����һ�����
 * @return redirect:admin/login.jsp" or index
 */
	@RequestMapping("findCategory")
	public String findCategory(Map<String, Object> map, HttpSession session) {
		AdminInfo userInfo = (AdminInfo) session.getAttribute(Const.USER_INFO);
		if (null == userInfo) {
			map.put("msg", "û�е�¼�����ȵ�¼");
			return "redirect:admin/login.jsp";
		} else {
			session.setAttribute("categoryList", categoryService.findCategory());
			return "index";
		}

	}
	/**
	 * @date 2017��8��4��) ����6:58:58
	 * @Package com.qc.ds.controller.backstage 
	 * @Description: TODO//������
	 */
	@RequestMapping(value="addCategory",produces="text/html;charset=utf-8")
	public String addCategory(Category vategory, HttpServletResponse response) throws IOException {
		response.setContentType("text/html;charset=utf-8");
		vategory.setcategoryName(new String(vategory.getcategoryName().getBytes("ISO-8859-1"),"utf-8"));
		
		PrintWriter out = response.getWriter();
		Boolean bl = categoryService.addCategory(vategory);
		if (bl) {
			out.write("<script>alert('��ӳɹ���');location.href='../../admin/index.jsp';</script>");
		} else {
			out.write("<script>alert('���ʧ�ܣ�');location.href='../.../admin/index.jsp';</script>");
		}
		return null;
	}
}
